using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class ChatroomMemberItem : UserControl, BaseHeadImgItem
	{
		public static DependencyProperty ListItemProperty = DependencyProperty.Register("ItemObject", typeof(Contact), typeof(ChatroomMemberItem), new PropertyMetadata(null, new PropertyChangedCallback(ChatroomMemberItem.OnItemPropertyChanged)));
		public static HeadImgLoadService mHeadImgLoadService = new HeadImgLoadService(true);
		internal Image HeadImg;
		internal EmojiText TitleTxt;
		private bool _contentLoaded;
		public event ListItemClick ItemClick;
		public Contact ItemObject
		{
			get
			{
				return (Contact)base.GetValue(ChatroomMemberItem.ListItemProperty);
			}
			set
			{
				base.SetValue(ChatroomMemberItem.ListItemProperty, value);
			}
		}
		public string UserName
		{
			get
			{
				return this.ItemObject.strUsrName;
			}
			set
			{
			}
		}
		public ChatroomMemberItem()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ChatroomMemberItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ChatroomMemberItem_Unloaded));
			this.InitBindResource();
		}
		private void ChatroomMemberItem_Unloaded(object sender, RoutedEventArgs e)
		{
			ChatroomMemberItem.mHeadImgLoadService.Delete(this);
		}
		private void ChatroomMemberItem_Loaded(object sender, RoutedEventArgs e)
		{
			ChatroomMemberItem.mHeadImgLoadService.Add(this);
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
		}
		private void InitBindResource()
		{
			this.TitleTxt.FontFamily = (FontFamily)Application.get_Current().get_Resources().get_Item("PhoneFontFamilySemiLight");
			this.TitleTxt.Foreground = R.theme.LISTA_NAME_WORD_BRUSH;
		}
		private void Button_Click(object sender, RoutedEventArgs e)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, e);
			}
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ChatroomMemberItem.ListItemProperty)
			{
				(dependencyObject_0 as ChatroomMemberItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as Contact);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshItem(Contact item)
		{
			if (item == null)
			{
				return;
			}
			this.TitleTxt.Text = ContactHelper.GetContactDisplayName(item);
			this.HeadImg.set_Source(HeadImgMgr.getHeadImage(item));
		}
		private void RefreshHeadImg()
		{
			if (string.IsNullOrEmpty(this.ItemObject.strUsrName))
			{
				return;
			}
			ImageSource headImage = HeadImgMgr.getHeadImage(this.ItemObject);
			if (headImage != this.HeadImg.get_Source())
			{
				this.HeadImg.set_Source(headImage);
			}
		}
		public void HeadImgLoaded()
		{
			this.RefreshHeadImg();
		}
		public void ScreenIn()
		{
		}
		public void ScreenOut()
		{
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/ChatRoom/ChatroomMemberItem.xaml", 2));
			this.HeadImg = (Image)base.FindName("HeadImg");
			this.TitleTxt = (EmojiText)base.FindName("TitleTxt");
		}
	}
}
